
#ifndef BNETPACKETSNIFFER_H
#define BNETPACKETSNIFFER_H

#include <qobject.h>
#include <qcstring.h>
#include <qwaitcondition.h>
#include <qvaluelist.h>

#include "PacketSnifferWorkerThread.h"

// WIN32 is checked by pcap.h 
#ifdef Q_OS_WIN
  #ifndef WIN32
    #define WIN32
  #endif
#endif

//////////////////////////////////////////////////////////////////////////////
// This is using cygwin's include area files.
// #include "sys/socket.h"
// #include "net/if.h"
// #include "netinet/tcp.h"
// #include "netinet/in_systm.h"
// #include "netinet/in.h"
// #include "netinet/ip.h"
// #include "signal.h"
#include "myHack.h"
//////////////////////////////////////////////////////////////////////////////

#include <pcap.h>

class PacketSniffer : public QObject
{
    Q_OBJECT
 public:

    enum FilterGroup
	{
	    None = 0,
	    Bnet,
	    Custom
	};
    
    PacketSniffer( QObject* parent = 0,
		   const char* name = 0,
		   const FilterGroup& filterGroup = None,
		   const QString& filter = "",
		   const bool& tcpOnly = false );
    ~PacketSniffer();

    bool initSuccess() const;

    QValueList<QByteArray> sniff();

 signals:
    void sniffed( const QByteArray& );

 private:
    // Unimplemented functions:
    PacketSniffer( const PacketSniffer& );
    PacketSniffer& operator=( const PacketSniffer& );
    
    bool initSuccess_;
    QValueList<QByteArray> byteArrays_;
    QValueList<PacketSnifferWorkerThread*> workerThreads_;
    QWaitCondition waitForPacket_;
    pcap_if_t *alldevs_;
    QString filter_;
    FilterGroup filterGroup_;
    bool tcpOnly_;
};



#endif
